package com.wzdigit.wms.wms.service.core.trsn;

import com.wzdigit.wms.basic.domain.order.TrsnDtlGoods;
import com.wzdigit.wms.basic.mapper.core.order.TrsnDtlGoodsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 库存交易凭证明细货品清单 服务类
 * </p>
 *
 * @author
 * @since 2021-01-19
 */
@Service
@Slf4j
public class TrsnDtlGoodsService {

    @Autowired
    TrsnDtlGoodsMapper trsnDtlGoodsMapper;

    /**
     * 根据入参实体新增一条记录
     *
     * @param trsnDtlGoods
     * @return
     */
    public TrsnDtlGoods addNewOne(TrsnDtlGoods trsnDtlGoods) {
        int row = trsnDtlGoodsMapper.insert(trsnDtlGoods);
        log.info("成功新增{}条记录", row);

        return trsnDtlGoods;
    }

    /**
     * 根据入参实体新增一条记录
     *
     * @param trsnDtlGoods
     * @return
     */
    public TrsnDtlGoods updateOne(TrsnDtlGoods trsnDtlGoods) {
        int row = trsnDtlGoodsMapper.updateById(trsnDtlGoods);
        log.info("成功更新{}条记录", row);

        return trsnDtlGoods;
    }

    /**
     * 根据入参集合新增记录
     *
     * @param trsnDtlGoodsList
     * @return
     */
    public List<TrsnDtlGoods> addNewList(List<TrsnDtlGoods> trsnDtlGoodsList) {
        for (TrsnDtlGoods trsnDtlGoods : trsnDtlGoodsList) {
            addNewOne(trsnDtlGoods);
        }

        return trsnDtlGoodsList;
    }

    /**
     * 根据入参集合更新记录
     *
     * @param trsnDtlGoodsList
     * @return
     */
    public List<TrsnDtlGoods> updateList(List<TrsnDtlGoods> trsnDtlGoodsList) {
        for (TrsnDtlGoods trsnDtlGoods : trsnDtlGoodsList) {
            trsnDtlGoods = updateOne(trsnDtlGoods);
        }
        return trsnDtlGoodsList;
    }
}
